package com.example.sqlitetest_test;

import java.util.Set;

import android.database.Cursor;
import android.test.AndroidTestCase;
import android.util.Log;

import com.example.student.ClassTable;
import com.example.student.SchemaHelper;

public class StudentTest extends AndroidTestCase {

	@Override
	protected void setUp() throws Exception {
		SchemaHelper sh = new SchemaHelper(getContext());
		// ADD STUDENTS AND RETURN THEIR IDS
		long sid1 = sh.addStudent("Jason Wei", "IL", 12);
		long sid2 = sh.addStudent("Du Chung", "AR", 12);
		long sid3 = sh.addStudent("George Tang", "CA", 11);
		long sid4 = sh.addStudent("Mark Bocanegra", "CA", 11);
		long sid5 = sh.addStudent("Bobby Wei", "IL", 12);
		// ADD COURSES AND RETURN THEIR IDS
		long cid1 = sh.addCourse("Math51");
		long cid2 = sh.addCourse("CS106A");
		long cid3 = sh.addCourse("Econ1A");
		// ENROLL STUDENTS IN CLASSES
		sh.enrollingStudentClass((int) sid1, (int) cid1);
		sh.enrollingStudentClass((int) sid1, (int) cid2);
		sh.enrollingStudentClass((int) sid2, (int) cid2);
		sh.enrollingStudentClass((int) sid3, (int) cid1);
		sh.enrollingStudentClass((int) sid3, (int) cid2);
		sh.enrollingStudentClass((int) sid4, (int) cid3);
		sh.enrollingStudentClass((int) sid5, (int) cid2);
		// GET STUDENTS FOR COURSE
		Cursor c = sh.getStudentForCourse((int) cid2);
		while (c.moveToNext()) {
			int colid = c.getColumnIndex(ClassTable.STUDENT_ID);
			int sid = c.getInt(colid);
			Log.d("---", "STUDENT " + sid + " IS ENROLLED IN COURSE " + cid2);
		}
		// GET STUDENTS FOR COURSE AND FILTER BY GRADE
		Set<Integer> sids = sh.getStudentByGradeForCourse((int) cid2, 11);
		for (Integer sid : sids) {
			Log.d("---", "STUDENT " + sid + " OF GRADE 11 IS ENROLLED IN COURSE "
					+ cid2);
		}
		sh.close();
	}

	@Override
	protected void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
	}

}
